<template>
  <div>
    <div class="chart" ref="myChart"></div>
  </div>
</template>

<script>
import {getBaiduSite} from "../api";

export default {
  name: 'RightBottom',
  data () {
    return {
      newArray: []
    }
  },
  methods: {
    init () {
      const getChartDom = this.$refs.myChart
      const myChart = this.$echarts.init(getChartDom, 'dark')
      myChart.setOption({
        title: {
          text: '月度风险状况'
        },
        tooltip: {},
        backgroundColor: 'rgb(14, 26, 45)',
        legend: {
          type: 'plain',
          right: '20px'
        },
        xAxis: {
          name: '月份',
          data: ['浏览量', '访问次数', '访客数', 'IP数']
        },
        yAxis: {
          name: '风险数'
        },
        series: [{
          name: '销量123',
          type: 'line',
          data: this.newArray
        }]
      });
    },
    getBaidu () {
      setInterval(() => {
        getBaiduSite().then(res => {
          this.newArray = []
          const obj = res.data.data
          for (const i in obj) {
            this.newArray.push(obj[i])
          }
        })
        this.init()
      }, 2000)
    }
  },
  mounted () {
    this.init()
    this.getBaidu()
  }
}
</script>

<style lang="scss" scoped>
@import "src/assets/scss/var_";

.chart {
  width: $right_chart;
  height: $bottom_height;
}
</style>
